package client;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Image;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class ImagePanel extends JPanel {
	private static final long serialVersionUID = 1L;
	private JLabel image;
	JButton but;
	private JTextArea text;
	private CardLayout card;
	private JPanel previewArea;
	
	public ImagePanel() {
		super();

		this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		previewArea = new JPanel();
		card = new CardLayout();
		previewArea.setLayout(card);
		
		image = new JLabel();
		image.setAlignmentX(CENTER_ALIGNMENT);
		previewArea.add(new JScrollPane(image), "constraint");
		
		text = new JTextArea();
		text.setEditable(false);
		previewArea.add(new JScrollPane(text), "constraint");
		
		this.add(previewArea);
		this.add(Box.createVerticalStrut(5));
		but = new JButton("Se connecter");
		but.setAlignmentX(CENTER_ALIGNMENT);
		but.setEnabled(false);
		this.add(but);
	}
	
	public void updatePreview(Image newImage) {
		image.setIcon(new ImageIcon(newImage));
		card.first(previewArea);
	}
	
	public void updatePreview(String str) {
		text.setText(str);
		card.last(previewArea);
	}
}
